﻿#pragma once

class CLocalStorage : public TNPObject<CLocalStorage>
{
public:
	CLocalStorage(NPP npp);
	virtual ~CLocalStorage();

	typedef bool (CLocalStorage::* METHOD)(const NPVariant *, uint32_t, NPVariant *);
private:
	std::map<std::string, METHOD>		m_methods;
	std::string                             m_rootpath;
public:
	bool	HasMethod(NPIdentifier name);
	bool	Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);

public:
	bool 	Method_update(const NPVariant *args, uint32_t argCount, NPVariant *result);
	bool    Method_setpath(const NPVariant *args, uint32_t argCount, NPVariant *result);
	bool    Method_getlist(const NPVariant *args, uint32_t argCount, NPVariant *result);
        bool    Method_getuuid(const NPVariant *args, uint32_t argCount, NPVariant *result);
public:
	typedef struct {
		CLocalStorage*      pthis;
		NPObject*           pobject;
	} THREAD_PARAMETER, *LPTHREAD_PARAMETER;

	typedef struct{
		NPP         npp;
		NPObject*   object;
		CNPVariant  param[5];
	} CALLBACK_PARAMETER, *LPCALLBACK_PARAMETER;
public:
	void DoUpdate(NPObject* pobject);
public:
	static void     EnumHtmlFiles(std::vector<std::string>& vct, const char* pDir);
	static void     callback_update(void *);
	static void     call_update(NPP npp, NPObject* object, long pos, const char* pmsg, ...);
	static void*  _stdcall  thread_update(void *);
};



